package main

import (
	"fmt"
	"net"
	"time"
)

var CONN net.Conn

func main() {
	// 服务器地址和端口
	serverAddr := "localhost:8150"

	// 建立TCP连接
	conn, err := net.Dial("tcp", serverAddr)
	if err != nil {
		fmt.Println("Error connecting:", err)
		return
	}
	CONN = conn
	defer CONN.Close()

	fmt.Println("Connected to server:", serverAddr)
	go sendMsg1()
	select {}
}

// 发送消息
func sendMsg1() {
	// 模拟设备发送消息
	for i := 0; i < 5; i++ {
		_, err := CONN.Write(AIData())
		if err != nil {
			fmt.Println("Error sending message:", err)
			return
		}
		// 等待一秒再发送下一条消息
		time.Sleep(time.Second * 10)
	}
}
